﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateWeldPoint.CApCreateWpEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;


namespace DnProcessSimulateCommands.CreateWeldPoint;

internal class CApCreateWpEnabler : ITxCommandEnabler
{
  private bool CheckEnable()
  {
    bool flag = false;
    if (TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded() && TxTcUtilities.IsTcAnyPlatform && (this.IsSelectionValid() || TxApplication.ActiveSelection.TotalCount == 0))
      flag = true;
    return flag;
  }

  private bool IsSelectionValid()
  {
    bool flag = true;
    if (TxTcUtilities.IsTcAnyPlatform)
    {
      CApCreateWpTCLogic capCreateWpTcLogic = new CApCreateWpTCLogic();
      TxTypeFilter txTypeFilter1 = new TxTypeFilter();
      if (!capCreateWpTcLogic.IsWeldPointPrivate)
      {
        TxTypeFilter txTypeFilter2 = new TxTypeFilter();
        foreach (Type allowedType in capCreateWpTcLogic.WeldContainerValidator.AllowedTypes)
        {
          txTypeFilter2.AddIncludedType(allowedType);
          txTypeFilter1.AddIncludedType(allowedType);
        }
        TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter2);
        if (filteredItems != null)
          flag = ((Collection<ITxObject>) filteredItems).Count == 0 || ((Collection<ITxObject>) filteredItems).Count == 1;
      }
      if (flag)
      {
        TxTypeFilter txTypeFilter3 = new TxTypeFilter();
        foreach (Type allowedType in capCreateWpTcLogic.WeldOperationValidator.AllowedTypes)
        {
          txTypeFilter3.AddIncludedType(allowedType);
          txTypeFilter1.AddIncludedType(allowedType);
        }
        TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter3);
        if (filteredItems != null)
          flag = ((Collection<ITxObject>) filteredItems).Count == 0 || ((Collection<ITxObject>) filteredItems).Count == 1 && ((Collection<ITxObject>) filteredItems)[0].CanBeModified;
      }
      if (flag && ((Collection<ITxObject>) TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter1)).Count != TxApplication.ActiveSelection.Count)
        flag = false;
    }
    return flag;
  }

  public bool Enable => this.CheckEnable();
}
